// 跳转详情
function toNewsDet(e) {
	location.href = 'article_details.html?articleid=' + e;
}
function toZdxmDet(e) {
	var data = zdxmDATA.find(function(i){
		return i.id === e
	})
	var d = encodeURIComponent(JSON.stringify(data));
	sessionStorage.setItem('zdxm',d)
	//console.log('toZdxmDet',e,zdxmDATA,data)

	location.href = 'zdxm_detail.html';
}
var zdxmDATA = [];
layui.use(['layer', 'laypage', 'dropdown'], function() {
	sessionStorage.setItem('zx', '政策指南');
	var layer = layui.layer;
	var laypage = layui.laypage;
	var dropdown = layui.dropdown
	var exnr = null;
	var pageOimh = {
		page: 1,
		rows: 10,
	};
	$('.nav_ul li').click(function(e) {
		$('.nav_ul li').removeClass('nav_bg_zx');
		$(this).addClass('nav_bg_zx');
		exnr = layer.load();
		pageOimh.page = 1;
		var codeStr = e.target.innerText;
		// 显示右侧菜单/重置筛选内容
		if (codeStr == '政策指南') {
			pageOimh.levelType = "";
			pageOimh.policyType = "";
			$('.newsClassify').show();
		} else {
			$('.newsClassify').hide();
		}
		$('.information-title').text(codeStr);
		sessionStorage.setItem('zx', codeStr);
		queryBmfv();
	});
	queryBmfv();

	function queryBmfv() {
		var codeStr = sessionStorage.getItem('zx');
		var ticket = localStorage.getItem('TICKET');
		$('.information-title').text(codeStr);
		if (!codeStr) {
			pageOimh.code = 'ZCRD';
			$('.information-title').text('政策指南');
			$('.nav_ul li').first().addClass('nav_bg_zx');
		} else {
			if (codeStr == '政策指南') {
				pageOimh.code = 'ZCRD';
			} else if (codeStr == '企业对接') {
				pageOimh.code = 'TZGG';
				$('.newsClassify').hide();
			} else if (codeStr == '新闻中心') {
				pageOimh.code = 'JRZX_JRXW';
				$('.newsClassify').hide();
			} else if (codeStr == '增值服务') {
				pageOimh.code = 'SJZCRD';
				$('.newsClassify').hide();
			} else if (codeStr == '重点项目') {
				pageOimh.code = 'ZDXM';
				$('.newsClassify').hide();
			}
			// 默认选中状态
			$('.nav_ul li').each(function() {
				if ($(this).find('span').text() == codeStr) {
					$(this).addClass('nav_bg_zx')
				}
			});
		}
		$.ajax({
			type: 'post',
			data: pageOimh,
			headers: {
				ticket: ticket
			},
			url: sdk.companyIp +
				'mh/app/xw/getNewXwPage',
			success: function(d) {
				if(pageOimh.code == 'ZDXM'){
					console.log('d',d)
					d.rows.forEach(function(i){
						i.createTime_show = sdk.timeFormat(i.createTime,'Y-M-D')
					});
					zdxmDATA = d.rows;
				}
				$('#news_body_item').html($.templates('#news_jsRender').render(d));
				
				setTimeout(function() {
					layer.close(exnr);
				}, 800)
				// 分页
				laypage.render({
					elem: 'pageDtia', //注意，这里的 test1 是 ID，不用加 # 号
					count: d.total, //数据总数，从服务端得到
					limit: pageOimh.rows,
					curr: pageOimh.page,
					theme: '#0487ff',
					jump: function(obj, first) {
						//首次不执行
						if (!first) {
							pageOimh.page = obj.curr;
							pageOimh.rows = obj.limit;
							queryBmfv();
						}
					}
				});
				
				if (codeStr == '重点项目'){
					$('#pageDtia').hide()
				}else{
					$('#pageDtia').show()
				}
				
				layer.close(exnr);
			},
			error: function(err) {
				layer.msg('系统错误,请联系管理员!', {
					icon: 5
				});
			}
		})
		layer.close(exnr);
	}

	// 日期对比
	function duibi(a, flag) {
		var arr = a.split("-");
		var starttime = new Date(arr[0], arr[1], arr[2]);
		var starttimes = starttime.getTime();
		var date = new Date();
		var YY = date.getFullYear() + '-';
		var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
		var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
		var today = YY + MM + DD
		var arrs = today.split("-");
		var endTime = new Date(arrs[0], arrs[1], arrs[2]);
		var endTimes = endTime.getTime();
		// 进行日期比较
		if (endTimes == starttimes) {
			flag = "true";
			return flag;
		} else {
			flag = "false";
			return flag;
		}
	};


	// 下拉选择新闻类型
	dropdown.render({
		elem: '#zcfl',
		data: [{
			title: '不限',
		}, {
			title: '金融政策',
		}, {
			title: '财政政策',
		}, {
			title: '产业政策',
		}],
		id: 'zcfl',
		click: function(obj) {
			if(obj.title == '不限'){
				delete pageOimh.policyType;
				$('#zcfl span').text('政策分类');
			}else{
				pageOimh['policyType'] = obj.title;
				$('#zcfl span').text(obj.title);
			}
			queryBmfv();
		}
	});

	dropdown.render({
		elem: '#zcjb',
		data: [{
			title: '不限',
		}, {
			title: '国家级',
		}, {
			title: '省级',
		}, {
			title: '地市级',
		}],
		id: 'zcjb',
		click: function(obj) {
			if(obj.title == '不限'){
				delete pageOimh.levelType;
				$('#zcjb span').text('政策级别');
			}else{
				pageOimh['levelType'] = obj.title;
				$('#zcjb span').text(obj.title);
			}
			queryBmfv();
		}
	});
});
